Introduction to data science in R
Lesson 8: Putting it all together
Brian S. Evans, Ph.D.
Migratory Bird Center
Smithsonian Conservation Biology Institute
# Load RCurl library:
library(RCurl)
# Load a source script:
script <-
getURL(
paste0(
'https://raw.githubusercontent.com/bsevansunc/workshop_languageOfR/master/',
'sourceCode_workshop.R'
)
)
# Evaluate then remove the source script:
eval(parse(text = script))
rm(script)
Code sections: Break larger file into discrete regions
Insert section head:
# Section 1
# Section 1 -----
# Section 1 ----*Code sections: Break larger file into discrete regions
Insert section head using CTRL(CMD)+SHIFT+R:
Code sections: Break larger file into discrete regions
Insert section head: Ctrl(Cmd)+Shift+R:
Code sections: Break larger file into discrete regions
Code sections: Break larger file into discrete regions
Code sections: Break larger file into discrete regions
Jump to: Shift+Alt+J
Code sections: Break larger file into discrete regions
Code sections: Break larger file into discrete regions
Fold all: Alt+O
Code sections: Break larger file into discrete regions
Expand
Code sections: Break larger file into discrete regions
Expand all: Shift+Alt+O
Explore the code sections of the file sourceCode_workshop.R. Use this file to do the following:
birdCounts and birdMeasures are in the same code section. Provide separate code sections for each data frame.
If you work on multiple projects, it is useful to separate tasks into R projects. An R project has its own:
Create a project in the directory where you are running the R files for this class.
R Notebooks are digital lab notebooks written in Markdown, a plain text formatting language.
R Notebooks are digital lab notebooks written in Markdown, a plain text formatting language.
R Markdown documents
R Markdown documents
R Markdown documents
R Markdown documents
R Markdown documents
R Markdown documents can also be written in html (like all of the presentations in this workshop).
Create a new R notebook. Copy-and-paste the code from the functions code section of sourceCodeWorkshop.R into the notebook document. Replace the comments with markdown text and wrap code sections for evaluation.
Scripts called source code can be run from within another script.
Scripts called source code can be run from within another script.
source('sourceCode_workshop.R')printHw <- function(){
"Hello world!"
}sourceFunctions.R in your current working directory.
printHw to remove the function from your environment.
source(`sourceFunctions.R`)
printHw()